package com.huali;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "LoginServlet", value = "/LoginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String username = request.getParameter("username");
        String password = request.getParameter("password");
        if ("123".equals(username)){
            if ("123".equals(password)){
                System.out.println("登录成功");
                Cookie cookie=new Cookie("huali","0322");
                response.addCookie(cookie);
                request.getRequestDispatcher("/successful.html").forward(request,response);
                return;
            }
        }
        System.out.println("登录失败");
        response.sendRedirect("/failing.html");

    }
}
